package TAIC.util;

import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.Vector;

public class SplitFile {
	public static void main ( String args [] ) throws Exception {
		if ( args.length != 2 ){
			System.out.println ( "please input the file to split and the number of splits" ) ;
			return ;
		}
		
		Scanner scanner = new Scanner ( new File ( args[ 0 ])) ;
		int splits = Integer.valueOf( args[ 1 ]) ;
		Vector < String > list = new Vector < String > () ;
		while ( scanner.hasNextLine () ) list.add( scanner.nextLine().trim() ) ;
		scanner.close();

		int num = ( list.size() + splits - 1 ) / splits ;
		for ( int i = 0 ; i < splits ;  i ++ ) {
			PrintStream fout = new PrintStream ( new File ( args[ 0 ] + "." + (i+1) )) ;
			int begin = num * i ;
			int end = begin + num ; 
			if ( end > list.size() ) end = list.size() ;
			for ( int j=  begin; j < end; j ++ ) fout.println ( list.get(j) ) ;
			fout.close(); 
		}
	}
}
